﻿(function () {
    var Vector2D = function (x, y) {
        this.x = x;
        this.y = y;
    };
    Vector2D.prototype = {
        minus: function (vector2d) {
            return (new Vector2D(this.x - vector2d.x, this.y - vector2d.y));
        },
        plus: function (vector2d) {
            return (new Vector2D(this.x + vector2d.x, this.y + vector2d.y));
        },
        scalarProduct: function (vector2d) {
            return (this.x * vector2d.x + this.y * vector2d.y);
        },
        multiply: function (number) {
            this.x = number * this.x;
            this.y = number * this.y;
        },
        rotate: function(angleInRadians){
            var sin = Math.sin(angleInRadians);
            var cos = Math.cos(angleInRadians);
            var oldX = this.x;

            this.x = this.x * sin - this.y * cos;
            this.y = oldX * cos + this.y * sin;
        },
        length: function () {
            return (Math.sqrt(this.x * this.x + this.y * this.y));
        },
        toString: function () {
            return ("(" + this.x + "," + this.y + ")");
        },
    };

    tetris.Vector2D = Vector2D;
})();